package com.qiusuo0226.core.controller;

import com.qiusuo0226.core.service.LoginService;
import com.qiusuo0226.mvc.util.JsonResultModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 需要token校验的相关前端控制层
 * @author qiusuo
 * @date 2023/6/19 15:41
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/manager/login")
public class LoginManagerController {

    @Autowired
    private LoginService loginService;

    /**
     * todo 退出登录
     * 首先进行token拦截器的拦截，校验发送IP和登录IP是否一致
     * 再校验退出用户ID和登录ID是否一致
     * @param userId 用户唯一标识
     * @return
     */
    @PostMapping("/sign_out")
    public JsonResultModel login(HttpServletRequest request, long userId) {
        // 获取请求的Token
        String token = request.getHeader("Authorization");
        // 登录结果
        return loginService.signOut(token, userId);
    }

    

    /**
     * 注册
     * @return
     */
    @PostMapping("/sign_up")
    public JsonResultModel register() {
        return JsonResultModel.requestError();
    }
}

